<template>
    <div class="wrapper">
		<div class="header">群组成员添加列表</div>
		<div class="content">
			<div class="search">
				<div class="text">
					<input type="text" placeholder="搜索">
				</div>
				<span class="search_btn"><img src="img/search_btn.png" alt=""></span>
			</div>
			<div class="list">
				
				<div class="list_wrapper" v-for="item in friendsList">
					<div class="list_item2">
						<div class="list_item2_left"><img :src="item.faceUrl" alt=""></div>
						<div class="list_item2_right">
							<span class="friend_name">{{item.Nick}}</span>
							<span class="friend_desc">一切就像是电影，比电影还要精彩</span>
						</div>
            <div @click="inviteJoinGroup(item.Info_Account)" >邀请加群</div>
					</div>
				</div>
			</div>
		</div>
		<!-- <div class="footer">
			<div class="footer_item">
				<i class="iconfont icon-duanxinqunfa"></i>
				<div class="controlo"><span>8</span></div>
			</div>
			<div class="footer_item">
				<i class="iconfont icon-kehuqunzu"></i>
				<div class="controlo"><span>100</span></div>
			</div>
			<div class="footer_item">
				<i class="active iconfont icon-user"></i>
				<div class="controlo"><span>99</span></div>
			</div>
		</div> -->
	</div>
</template>
<script>
  import $ from 'jquery'
  import Client from '../../config/common'
  export default {
    data () {
      return {
        loginInfo: {},
        friendsList: {}
      }
    },
    created () {

      // 登录初始化
    	this.initLogin();
      
    },
    methods: {

      // 登录初始化
			initLogin() {
				Client.login(this.getLoginInfo);
			},

			// 获得登录成功信息
			getLoginInfo(loginInfo){
				// 将 登录信息保存在 vue的data里
				this.loginInfo = loginInfo;
				Client.log("登录成功获取登录信息-start");
				Client.log(loginInfo);
        Client.log("登录成功获取登录信息-end");
        
        // 获取邀请加群的好友列表
        this.getMyFriendGroup();
        
      },
      // 邀请加群
      inviteJoinGroup(friend_id) {
          this.addGroupMember(friend_id);
      },

      // 邀请好友加群动作
      addGroupMember(friend_id) {
            var options = {
                'GroupId': Client.getQueryString("currentGroupId"),
                'MemberList': [{
                        'Member_Account': friend_id
                    }

                ]
            };
            webim.addGroupMember(
                options,
                function (resp) {
                    //在表格中删除对应的行
                    // $('#get_my_friend_group_table').bootstrapTable('remove', {
                    //     field: 'Info_Account',
                    //     values: [$('#agm_account').val()]
                    // });
                    // $('#add_group_member_dialog').modal('hide');
                    alert('邀请好友加群成功');
                },
                function (err) {
                    alert(err.ErrorInfo);
                }
            );
       },

      // 获取我的好友，然后邀请加群
      getMyFriendGroup() {
          let That = this;
          let options = {
              'From_Account': this.loginInfo.identifier,
              'TimeStamp': 0,
              'StartIndex': 0,
              'GetCount': 20,
              'LastStandardSequence': 0,
              "TagList": [
                  "Tag_Profile_IM_Nick",
                  "Tag_Profile_IM_Image",
                  "Tag_SNS_IM_Remark"
                  
              ]
          };

          webim.getAllFriend(
              options,
              function(resp) {
                  Client.log("邀请好友加群的好友列表-start");
                  Client.log(resp);
                  Client.log("邀请好友加群的好友列表-end");

                  if (resp.FriendNum > 0) {
                      let table_friends_data = [];
                      let friends = resp.InfoItem;
                      if (!friends || friends.length == 0) {
                          alert('你目前还没有好友，无法邀请好友加入该群');
                          return;
                      }
                      let count = friends.length;

                      for (let i = 0; i < count; i++) {
                          let friend_name = friends[i].Info_Account;
                          let friend_faceUrl = '';
                          if (friends[i].SnsProfileItem && friends[i].SnsProfileItem[0] && friends[i].SnsProfileItem[0].Tag) {
                              friend_name = friends[i].SnsProfileItem[0].Value;
                          }
                          if (friends[i].SnsProfileItem && friends[i].SnsProfileItem[1] && friends[i].SnsProfileItem[1].Tag) {
                              friend_faceUrl = friends[i].SnsProfileItem[1].Value;
                          }
                          console.log(11)
                          console.log(friends[i])                          
                          console.log(11)

                          table_friends_data.push({
                              'Info_Account': webim.Tool.formatText2Html(friends[i].Info_Account),
                              'Nick': webim.Tool.formatText2Html(friend_name),
                              'faceUrl': friend_faceUrl
                          });
                      }
                      That.friendsList = table_friends_data;
                      Client.log("邀请好友信息数据-starat");
                      Client.log(That.friendsList);
                      Client.log("邀请好友信息数据-end");
                      
                      //打开我的好友列表对话框
                      // $('#get_my_friend_group_table').bootstrapTable('load', table_friends_data);
                      // $('#get_my_friend_group_dialog').modal('show');

                  } else {
                      alert('你目前还没有好友，无法邀请好友加入该群');
                  }

              },
              function(err) {
                  alert(err.ErrorInfo);
              }
          );
      }
      
    }
  }
  
</script>
<style lang="scss">
  @import "../../style/group_add_member_from_friends";
</style>
